#!/bin/bash
# 设置变量
SERVICE_NAME="binance_vegas"  # 替换为你的服务的名称

# 查找旧服务并杀掉
echo "Stopping old service..."
PID=$(ps -ef | grep "${SERVICE_NAME}" | grep -v grep | awk '{print $2}')

if [ -n "$PID" ]; then
  echo "Killing process $PID..."
  kill -9 $PID
  if [ $? -eq 0 ]; then
    echo "Old service stopped."
  else
    echo "Failed to stop old service."
  fi
else
  echo "No old service running."
fi

# 启动新服务
echo "Starting new service..."
# 设置日志级别
export RUST_LOG=info

# 可执行文件路径
EXECUTABLE=/data01/binance_vegas/target/release/binance_vegas

# 日志文件路径（可选）
LOG_FILE=/data01/binance_vegas/logs/binance_vegas.log

# 后台启动程序，并将日志输出到文件
nohup $EXECUTABLE > $LOG_FILE 2>&1 &

# 记录进程 ID
echo $! > binance_vegas.pid

echo "binance_vegas程序启动成功!"
sleep 2
tail -100f /data01/binance_vegas/logs/binance_vegas.log

if [ $? -eq 0 ]; then
  echo "New service started."
else
  echo "Failed to start new service."
fi